home *** CD-ROM | disk | FTP | other *** search
- Path: jaxnet.jaxnet.com!jax!garyg
- From: garyg@jax.jaxnet.com (Gary M. Greenberg)
- Newsgroups: comp.lang.c
- Subject: Re: Character string
- Date: 11 Apr 1996 22:23:12 GMT
- Organization: Southeast Network Services, Inc.
- Message-ID: <4kk0og$ifu@jaxnet.jaxnet.com>
- References: <4kil74$8i7@Tandem1.opennet.net.au>
- NNTP-Posting-Host: jax.jaxnet.com
- X-Newsreader: TIN [version 1.2 PL2]
-
- Kenneth H Smith (george@opennet.net.au) wrote:
- : How do I do a similar statement in C to the Pascal code:
-
- : If Ch IN ['a','A'] THEN
- : I want to execute a piece of code when a particular character is entered
- : from the keyboard.
-
- : I know I can use if (ch=='a') && (ch=='A') but was looking for something
- : a little more ellegant.
- ^^^ inelegant. Elegant ;-)
-
- And, if you declare "char ch;" and then look for a character such that
-
- if(ch=='a' && ch=='A') ...
-
- you'll not find it; ch won't be both simultaneously.
-
- You want
-
- if(ch=='a' || ch=='A')
- whatever;
-
- I don't find it inelegant, but if you want a range of values,
- you are probably better off to either (a) use a switch statement, or
- (b) build a state machine.
-
- : Thanks,
-
- You're welcome.
-
- : Ken Smith.
-
- gary /* the Sorcerer's Apprentice */
- Contribute to the Randal Schwartz Legal Defense Fund
- Get FREE ANSI C E-Mail Management Source Code
- Visit: http://jax.jaxnet.com/~garyg/main_page.html
-